package cn.copera.dyy.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.copera.dyy.common.service.BaseService;
import cn.copera.dyy.dao.OrderDao;
import cn.copera.dyy.entity.Order;
import cn.copera.dyy.entity.UserShop;

/**
 * 用户列表顺序Service
 * 
 */
@Service
@Transactional(readOnly = true)
public class OrderService extends BaseService {
	@Autowired
	private OrderDao orderDao;

	@Transactional(readOnly = false)
	public void save(Order order) {
		orderDao.clear();
		orderDao.save(order);
	}

	public List<Order> findById(String id){
		return orderDao.find("from Order where shop.id = '"+id+"'");
	}
	
	public Order findOrder(String shopId,String openid){
		List<Order> list = orderDao.find("from Order where shop.id = '"+shopId+"' and openid = '"+openid+"'");
		if (list.isEmpty()) {
			return null;
		}else {
			return list.get(0);
		}
		//return orderDao.findExistEntity(new Order(), "shop.id = '"+shopId+"' and openid = '"+openid+"'");
	}
}
